package com.core.common.gen;

import com.baomidou.mybatisplus.core.metadata.IPage;
import com.baomidou.mybatisplus.extension.service.IService;
import org.springframework.util.CollectionUtils;

import java.util.*;

public interface IBaseService<T> extends IService<T> {

    default IPage<T> fuzzySearch(String searchText){
        return fuzzySearch(searchText,null,null,false);
    }

    IPage<T> fuzzySearch(String searchText,Integer pageNo,Integer pageSize,boolean isSearchCount);

    default IPage<T> selectPage(BaseQuery baseQuery){
        return selectPage(null,baseQuery,true);
    }
    default IPage<T> selectPage(BaseQuery baseQuery,boolean isSearchCount){
        return selectPage(null,baseQuery,isSearchCount);
    }

    default IPage<T> selectPage(T t,BaseQuery baseQuery,boolean isSearchCount){
        return selectPage(t, baseQuery,true,isSearchCount);
    }

    IPage<T> selectPage(T t,BaseQuery baseQuery,boolean copyBean,boolean isSearchCount);


    default T selectLimitOne(BaseQuery queryBean) {
        List<T> list=Optional.ofNullable(selectList(queryBean))
                .orElse(Collections.EMPTY_LIST);
        if (! list.isEmpty()){
            return list.get(0);
        }
        return null;
    }

    List<T> selectList(T t,BaseQuery queryBean);

    default List<T> selectList(BaseQuery queryBean) {
        return selectList(null,queryBean);
    }



    /**
     * 可能存在业务重复的批量保存
     * @param list
     * @param queryBean
     * @param repeatMode  重复处理模式(非主键)0 不处理 1 覆盖 2 删除 3 剔除
     * @return
     */
    boolean saveBatchWithRepeat(List<T> list,BaseQuery queryBean,int repeatMode) throws Exception;

    boolean removeByConditions(T t,BaseQuery queryBean);


}
